#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

class Solution {
public:
    vector<string> findOcurrences(string text, string first, string second) {
        vector<string> ret;
        vector<string> words;

        string textNew = text + " ";
        int textNewLen = textNew.length();
        if (textNewLen < first.length() + second.length()) {
            return ret;
        }

        while(textNew.length() != 0) {
            string strTmp = textNew.substr(0, textNew.find(' '));
            words.push_back(strTmp);
            textNew = textNew.substr(textNew.find(' ') + 1);
        }

        for (int idx = 2; idx < words.size(); idx++) {
            if ((words[idx - 2] == first) && (words[idx - 1] == second)) {
                ret.push_back(words[idx]);
            }
        }
        
        return ret;
    }
};

int main()
{
    Solution s;
    string text =  "alice is a good girl she is a good student";
    vector<string> ret = s.findOcurrences(text, "a", "good");

    for (const auto& elem : ret) {
        cout << elem << endl;
    }
    return 0;
}